#!/bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

echo "42.48.30.93  mirrors.hunantv.com" >> /etc/hosts

echo "- yum repo ..."
curl -s http://mirrors.hunantv.com/install_hunantv_repo.sh | sh

echo "- yum base rpms (ntpdate, proxychains, python-setuptools, python-meld3...) ..."
yum -y install wget ntpdate man proxychains python-setuptools python-meld3 python-devel kernel

chkconfig --add ntpd
chkconfig ntpd on
/etc/init.d/ntpd start

echo "- install pip ..."
easy_install pip

if ! [ -f /root/.pip/pip.conf ]; then
    mkdir -p /root/.pip
    echo '
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
' >> /root/.pip/pip.conf
fi

echo "- install and config supervisor .."
pip install supervisor redis chardet

mkdir -p /etc/supervisord.conf.d
if ! [ -f /etc/supervisord.conf ]; then
    wget -q http://mirrors.hunantv.com/d/supervisord.conf -O /etc/supervisord.conf
fi

echo "- java install ..."
if ! [ -d /opt/app/jdk1.7.0_45 ]; then
    mkdir -p /opt/app
    wget -q http://mirrors.hunantv.com/d/jdk-7u45-linux-x64.tar.gz -O /opt/app/jdk-7u45-linux-x64.tar.gz
    cd /opt/app
    tar xzf jdk-7u45-linux-x64.tar.gz -C /opt/app/
fi
if ! egrep '^JAVA_HOME=' /etc/profile &> /dev/null ; then 
    echo '
JAVA_HOME=/opt/app/jdk1.7.0_45
CLASSPATH=.:$JAVA_HOME/lib.tools.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH
' >> /etc/profile
fi

#echo "- install python2.7 ..."
#if ! [ -f /usr/local/bin/python2.7 ] ; then 
#    yum -y install gcc make gcc-c++
#
#    yum -y install  zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel openssl
#
#    mkdir -p /opt/src
#    cd /opt/src
#    rm -f Python-2.7.10.tgz
#    wget -q http://mirrors.hunantv.com/d/Python-2.7.10.tgz
#    tar xzf Python-2.7.10.tgz
#    cd Python-2.7.10
#    ./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib" --with-ensurepip=install
#    make && make altinstall
##
###    /usr/local/bin/pip2.7 install --upgrade pip
#fi
#
#php2.7 install redis chardet

#pip2.7 install redis

echo "- install zabbix ..."

echo "- ldap ..."
